package com.ckcool.api.controller;


import com.ckcool.api.service.LingXingInterfaceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Resource
    private LingXingInterfaceService lingXingInterfaceService;

    /**
     * 获取token
     * @return String
     * @throws Exception 异常
     */
    @GetMapping("/getToken")
    public String getToken() throws Exception {
        System.out.println(lingXingInterfaceService.getToken());
        return lingXingInterfaceService.getToken();
    }

    /**
     * 根据sku获取产品信息
     * @param sku 商品sku
     * @throws Exception 异常
     */
    @GetMapping("/getInfo")
    public void getInfo(String sku) throws Exception {
        lingXingInterfaceService.syncProductInfo(sku);
    }

    /**
     * 添加产品
     * @param sku 老sku
     * @param newSku 新sku
     * @param addSku 裸品sku
     * @throws Exception 异常
     */
    @GetMapping("/addProduct")
    public void addProduct(String sku,String newSku,String addSku) throws Exception {
        lingXingInterfaceService.addProductSku(sku,newSku,addSku);
    }

    /**
     * 批量添加产品
     * @throws Exception异常
     */
    @GetMapping("/addProducts")
    public void addProducts() throws Exception {
        lingXingInterfaceService.processProductSkuMappings();
        System.out.println("处理完成");
    }
}
